package io.adrainty.bolee.security.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.adrainty.bolee.framework.commons.basic.ResultDTO;
import io.adrainty.bolee.framework.commons.utils.ResultDTOUtil;
import io.adrainty.bolee.security.models.entity.RoleEntity;
import io.adrainty.bolee.security.service.IRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author AdRainty
 * @version V1.0.0
 * @since 2025/8/11 下午10:57
 */

@Tag(name = "角色管理")
@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private IRoleService roleService;

    @PostMapping("/page/{pageNum}/{pageSize}")
    @Operation(summary = "分页获取角色")
    public ResultDTO<IPage<RoleEntity>> findRolePage(@RequestBody RoleEntity entity,
                                                     @PathVariable("pageNum") Integer pageNum,
                                                     @PathVariable("pageSize") Integer pageSize) {
        IPage<RoleEntity> pageResult = roleService.findRolePage(entity, pageNum, pageSize);
        return ResultDTOUtil.success(pageResult);
    }

    @PutMapping
    @Operation(summary = "角色添加")
    public ResultDTO<RoleEntity> createRole(@RequestBody RoleEntity entity) {
        RoleEntity result = roleService.createRole(entity);
        return ResultDTOUtil.success(result);
    }

    @PatchMapping
    @Operation(summary = "角色修改")
    public ResultDTO<Boolean> updateRole(@RequestBody RoleEntity entity) {
        Boolean result = roleService.updateRole(entity);
        return ResultDTOUtil.success(result);
    }

    @PostMapping("/list")
    @Operation(summary = "角色列表")
    public ResultDTO<List<RoleEntity>> listRole(@RequestBody RoleEntity entity) {
        List<RoleEntity> result = roleService.listRole(entity);
        return ResultDTOUtil.success(result);
    }

}
